function printStar(n) {
  for (let i = 1; i < n + 1; i++) {
    // 最长的长度是2*n-1
    let count = 2 * i - 1
    let str1 = ''
    for (let j = 0; j < (2 * n - 1 - count) / 2; j++) {
      str1 += ' '
    }
    let str2 = ''
    for (let k = 0; k < count; k++) {
      str2 += '*'
    }
    let str3 = ''
    for (let l = 0; l < (2 * n - 1 - count) / 2; l++) {
      str3 += ' '
    }
    console.log(str1 + str2 + str3)
  }
  for (let i = n - 1; i > 0; i--) {
    count = 2 * i - 1
    let str1 = ''
    for (let j = 0; j < (2 * n - 1 - count) / 2; j++) {
      str1 += ' '
    }
    let str2 = ''
    for (let k = 0; k < count; k++) {
      str2 += '*'
    }
    let str3 = ''
    for (let l = 0; l < (2 * n - 1 - count) / 2; l++) {
      str3 += ' '
    }
    console.log(str1 + str2 + str3)
  }
}
printStar(7)
